<!DOCTYPE html>
<html>
<html  xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">

    <title></title>
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.css">
    <link href="https://cdn.bootcss.com/jquery-mobile/1.4.5/jquery.mobile.theme.css" rel="stylesheet">

    <script src="http://code.jquery.com/jquery-1.8.3.min.js"></script>
    <script src="http://code.jquery.com/mobile/1.3.2/jquery.mobile-1.3.2.min.js"></script>
    <script type="text/javascript">
        $(function () {
            //加载下拉框数据
            loadMeetingType();
            //加载可抢单列表
            loadGrabListByUidAndTid(0);
        })

        //加载可抢单列表
        function loadGrabListByUidAndTid(tid) {
            $("#grabNum").empty();
            $("#grabDiv").empty();

           var uid=$("#uid").val();
            $.ajax({
                type:"post",
                url:"/meetingGrab/grabListByUid",
                data:{"uid":uid,"tid":tid},
                success:function(objs){
                    if(objs.code=="2000"){

                        var dataObjs=objs.data;
                        $("#grabNum").append(dataObjs.length);

                        var appendHtml=""; //grabDiv
                        for(var i=0;i<dataObjs.length;i++){
                            mname=dataObjs[i].title;
                            remark=dataObjs[i].meetingType.name;
                            dateCurr=dataObjs[i].pcode;
                            pid=dataObjs[i].id;
                            appendHtml += "<div style='width: 100%;background-color: white;margin-top: -3px;padding:10px 10px 10px 15px;display: inline-block;'>" +
                                "<div style='width: 70%;float: left;' onclick='showMeetingInfo(\"" + 1 + "\");'>" +
                                "<div style='white-space: nowrap;overflow: hidden;text-overflow:ellipsis;display: block;font-size:18px;'>" +
                                mname + "</div>" +
                                "<div style='white-space: nowrap;overflow: hidden;text-overflow:ellipsis;display: block;color: #777777;font-size:16px;padding-top:1px'>" +
                                remark + " / " + dateCurr + "</div></div>" +
                                "<div style='width: 30%;float: right;'>" +
                                "<button class='able-btn' onclick='addMeetingGrab(\""+pid+"\")' >可抢单</button></div></div>";
                                                        //"onclick='addMeetingGrab("aaa")' "
                        }
                        $("#grabDiv").append(appendHtml);

                    }else if(objs.code=="4003"){
                        alert("错误的请求");

                    }

                }

            });
        }

        //进行抢单功能
        function addMeetingGrab(pid){

            //表单跳转，window..
            var uid=$("#uid").val();
            window.location.href="/meetingGrab/addMeetingGrabToPage?uid="+uid+"&pid="+pid;

        }


        //加载下拉框数据
        function loadMeetingType(){
            $.ajax({
                type:"get",
                url:"/meetingType/list",
                success:function(objs){

                    var appendHtml="<option value='0'>可抢单</option>";

                    if(objs.code=="2000"){
                        var obj=  objs.data;
                        for(var i=0;i<obj.length;i++){
                            var id=obj[i].id;
                            var name=obj[i].name;
                            appendHtml+="<option value='"+id+"'>"+name+"</option>";

                        }
                        $("#tid").append(appendHtml);

                    }
                }

            });

        }


        function showPubDiv() {
            $("#two_line").css("border-top", "5px solid #4E90C7");
            //$("#two_tab").css("color","#777777");
            $("#one_line").css("border-top", "5px solid white");
            //$("#one_tab").css("color","white");
            $("#two").css("display", "none");
            $("#one").css("display", "block");
        }

        function showMyMeetings() {

            $("#two_line").css("border-top", "5px solid white");
            $("#one_line").css("border-top", "5px solid #4E90C7");

            $("#one").css("display", "none");
            $("#two").css("display", "block");

            $("#two").empty();

           var uid= $("#uid").val();
            $.ajax({
                type:"get",
                url:"/meetingGrab/grabListByMyUid",
                data:{"uid":uid},
                success:function(objs){
                    if(objs.code=="2000"){

                        var objData=objs.data;

                        var appendHtml = "<font style='padding: 10px 10px 10px 15px;display: block;color: #777777;'>您共抢了"+objData.length+"场会议</font>";
                        for(var i=0;i<objData.length;i++){
                            var mname=objData[i].title;
                            var remark=objData[i].meetingType.name;
                            var dateCurr=objData[i].pcode;
                            var grabStatus=objData[i].meetingGrab.grabStatus;


                            appendHtml += "<div style='width: 100%;background-color: white;margin-top: -3px;padding:10px 10px 10px 15px;display: inline-block;'>" +
                                "<div style='width: 70%;float: left;' onclick='showMeetingInfo(\"" + 1 + "\");'>" +
                                "<div style='white-space: nowrap;overflow: hidden;text-overflow:ellipsis;display: block;font-size:18px;'>" +
                                mname + "</div>" +
                                "<div style='white-space: nowrap;overflow: hidden;text-overflow:ellipsis;display: block;color: #777777;font-size:16px;padding-top:1px'>" +
                                remark + " / " + dateCurr + "</div></div>" +
                                "<div style='width: 30%;float: right;'>" ;
                                if(0==grabStatus){
                                    appendHtml+="未审批";
                                }else if(1==grabStatus){
                                    appendHtml+= "<button class='able-btn' >匹配成功</button>" ;
                                }else{
                                    appendHtml+="匹配失败";
                                }

                                appendHtml+="</div></div>";

                        }
                        $("#two").append(appendHtml);
                    }
                }
            });



        }
    </script>
</head>

<body>
<div data-role="page" id="pageDetail">
    <input type="hidden" id="uid" name="uid" th:value="${uid}" />
    <div style="padding:0px;background-color: #4E90C7;width: 100%;height:40px;line-height:40px;font-size:18px;text-align: center;cursor: pointer;" data-role="none">
        <div style="width: 50%;float: left;color: white;" onclick="showPubDiv();" id="one_tab">
            抢单
            <div style="border-right: 1px solid white;float: right;margin-top: 10px;height: 20px;"></div>
        </div>
        <div style="width: 50%;float: left;color: white;" onclick="showMyMeetings();" id="two_tab">我的抢单</div>
        <div style="border-top:5px solid white;width: 50%;float: left;" id="one_line"></div>
        <div style="border-top:5px solid #4E90C7;width: 50%;float: left;" id="two_line"></div>
    </div>
    <div id="one" class="ui-body-d ui-content" style="padding:0;display: block;width: 100%;">
        <div style="padding:0 0 0 15px;display: block;width: 55%;float: left;line-height: 60px;color: #777777;">
            可参与<font id="grabNum"></font>场会议的抢单
        </div>
        <div style="width: calc(45% - 15px);float: right;">
            <select id="tid"  onchange="loadGrabListByUidAndTid(this.value)">

            </select>
        </div>
        <div id="grabDiv" style="width: 100%;float: left;">


        </div>
    </div>





    <div id="two" class="ui-body-d ui-content" style="padding: 0;display: none;width: 100%;">

    </div>
</body>

</html>